package com.example.demo.activemq.topic;

import com.example.demo.activemq.model.ActiveModel;
import com.example.demo.activemq.model.MessageModel;

public class TopicTest {
    public static void main(String[] args) {
        Thread thread = null;
        try {
            new AsynTopicConsumer("AsynTopicConsumer");
            new TopicConsumer("TopicConsumer");
            thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        //启动生产者
                        TopicProducer topicProducer = new TopicProducer("TopicProducer");
                        ActiveModel activeModel_1 = new MessageModel(100001, "hello world!!!");
                        ActiveModel activeModel_2 = new MessageModel(100002, "hello world!!!");

                        topicProducer.sendMessage(activeModel_1);
                        topicProducer.commit();

                        topicProducer.sendMessage(activeModel_2);
                        topicProducer.commit();

                        Thread.sleep(2000);
                        topicProducer.sendFinishMessage();
                        topicProducer.commit();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            thread.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
